package com.woniuxy.config;

import com.woniuxy.po.RoutingKeysForDirect;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Author: 马宇航
 * Do: 直连交换机配置，必须指定routingkey！！！！交换机和队列之间的routingkey必须全匹配才能发送到对应的队列！
 * DateTime: 22/07/06/0006 下午 4:06
 * Component: 成都蜗牛学苑
 * <img src="https://woniumd.oss-cn-hangzhou.aliyuncs.com/java/mayuhang/202207032353326.png"/>
 **/
@Configuration
public class DirectExchangeConfig {
    /**
     * 创建两个队列
     * ChangeLog : 1. 创建 (22/07/06/0006 下午 4:09 [马宇航]);
     *
     * @return org.springframework.amqp.core.Queue
    */
    @Bean
    public Queue dQueue1(){
        return new Queue("directQueue1");
    }
    @Bean
    public Queue dQueue2(){
        return new Queue("directQueue2");
    }
    /**
     * 创建广播模式的交换机
     * ChangeLog : 1. 创建 (22/07/06/0006 下午 4:09 [马宇航]);
     *
     * @return org.springframework.amqp.core.FanoutExchange
    */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct");
    }
    /**
     * 队列和交换机绑定
     * ChangeLog : 1. 创建 (22/07/06/0006 下午 4:11 [马宇航]);
     *
     * @return org.springframework.amqp.core.Binding
    */
    @Bean
    public Binding bindingDirect1(){
        //绑定队列和广播交换机，必须指定routingkey
        return BindingBuilder.bind(dQueue1()).to(directExchange()).with("*.orange");
    }
    @Bean
    public Binding bindingDirect2(){
        //绑定队列和广播交换机
        return BindingBuilder.bind(dQueue2()).to(directExchange()).with(RoutingKeysForDirect.green);
    }
    @Bean
    public Binding bindingDirect3(){
        //绑定队列和广播交换机
        return BindingBuilder.bind(dQueue2()).to(directExchange()).with(RoutingKeysForDirect.black);
    }
}
